<?php

declare(strict_types=1);

namespace App\Service;

/**
 * 用户文章关联关系服务类
 * 用于取得用户关联文章的一些数据
 * 作者 薛原
 * 日期 2025-10-17
 */
use App\Model\Article;
use App\Repository\UserArticleRepository;
use Hyperf\Di\Annotation\Inject;

class UserArticleService
{
    #[Inject]
    private UserArticleRepository $userArticleRepository;


    /**
     * 用户文章数统计
     * @param $user_id
     * @return int
     */
    public function getUserArticleCount($user_id)
    {
        return $this->userArticleRepository->getArticleCount($user_id);
    }

    /**
     * 用户关注数统计
     * @param $user_id
     * @return int
     */
    public function getUserFollowerCount($user_id)
    {
        return $this->userArticleRepository->getUserFollowerCount($user_id);
    }

    /**
     * 用户被关注数统计
     * @param $user_id
     * @return int
     */
    public function getUserFolloweringCount($user_id)
    {
        return $this->userArticleRepository->getUserFolloweringCount($user_id);
    }
    /**
     * 用户文章被浏览数
     * @param $user_id
     * @return int
     */
    public function getUserArticleViewCount($user_id)
    {
        return $this->userArticleRepository->getUserArticleViewCount($user_id);
    }

    /**
     * 整合用户文章统计相关
     * @param $user_id
     * @return array
     */
    public function getUserStatsData($user_id):array
    {
        $obj = [];
        $obj['article_count'] = $this->getUserArticleCount($user_id);
        $obj['follower_count'] = $this->getUserFollowerCount($user_id);
        $obj['following_count'] = $this->getUserFolloweringCount($user_id);
        $obj['total_views'] = $this->getUserArticleViewCount($user_id);
        return $obj;
    }
}